<?php
namespace app\operation\controller;
use app\common\controller\OperationBase;
/*android 设备启动记录*/
class DeviceLog extends OperationBase{
	protected $beforeActionList = [
        'before_index'=>['only'=>'index'],
    ];
	function _initialize() {
		parent::_initialize();  
    }
	function index(){
		$this->assign("shops",db("Shop")->where("parent_id!=0")->order("id desc")->field("shop_name,id,parent_id")->select());
		echo $this->fetch();
	}	
	function ajax_index(){
		$this->ajax($this->_ajax_index());
	}
	///////////////////////////////////////////////////////////////////////////////////
	/**
	 * 权限菜单
	 **/
	function before_index(){
		$auth_group=sp_get_auth_menu_3("20061004");
		$this->assign("menus",$auth_group);
	}
	
	private function _ajax_index(){
		$query=array(
						'machine_type'=>array("field" =>"a.machine_type","operator" =>"="),
						'brand_code'=>array("field" =>"a.brand_code","operator" =>"="),
					 );
		$draw=input("draw",0)+1;//请求时间		 
		$where_and=join(" and ",sp_get_param_sql(request()->isPost(),$query));
		$shop_id=input("shop_id/d",0);
		if(!empty($shop_id))	{
			$where_and.=" and a.shop_id=$shop_id ";
		} 
		$start=input("start_date");
		$end=input("end_date");
		$where_and.=" and TO_DAYS(a.create_time)>=TO_DAYS('$start') and TO_DAYS(a.create_time)<=TO_DAYS('$end')";
		$total=db("DeviceLog")->alias("a")->join([['m_shop b','a.shop_id=b.id','left']])->where($where_and)->fetchsql(FALSE)->count(1);
		$list=db("DeviceLog")->field("a.*,b.shop_name")->alias("a")->join([['m_shop b','a.shop_id=b.id','left']])->where($where_and)->order($this->get_order())->limit($this->get_limit())->fetchsql(FALSE)->select();
		//权限
		return array('pageData'=>$list,'total'=>$total,"draw"=>$draw);
	}
}
